package com.itheima.reggie.common;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.math.BigInteger;

public class JacksonObjectMapper extends ObjectMapper {
    public JacksonObjectMapper(){
        super();
        //不报异常
//        this.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,false);
        this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        //2.
        this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);

        //3.自定义转换规则
        //将biginter转换为String类型，将long转换为string类型
        SimpleModule simpleModule = new SimpleModule().addSerializer(BigInteger.class, ToStringSerializer.instance).addSerializer(Long.class,ToStringSerializer.instance);

        this.registerModule(simpleModule);

    }


}
